var _UIContainer = require('component/uicontainer.js');
var _inherit = require('core/inherit.js');
var _Event = require('component/event.js');

function Scene() {
    _UIContainer.call(this);
    this.mEvents = new _Event();
    this.mTimestamp = 0;
    this.mId = '';
}
_inherit(Scene, _UIContainer);
Scene.prototype.mTag = 'scene';
Scene.prototype.__elementType |= Scene.prototype.ElementTypeScene;
Scene.prototype.update = function (context) {
};
Scene.prototype.onTouch = function (event) {
};
Scene.prototype.onSizeChange = function (w, h) {
};
Scene.prototype.onRegister = function (global) {
    global.scheduleRender.schedule(this);
    global.scheduleUpdate.schedule(this);
    global.scheduleEvent.schedule(this);
};
/**
 * create a anonymous scene class, this scene may used many times
 *
 * @param init
 * @param props
 * @returns {*}
 */
Scene.createScene = function (init, props) {
    var clz = _inherit(function () {
        Scene.call(this);
    }, Scene, props);

    var instance;
    /**
     * @param id
     * @returns {clz}
     */
    clz.newInstance = function (id) {
        var instance = new clz(id);
        init.apply(instance, arguments);
        return instance;
    };
    clz.singleInstance = function () {
        return instance || (instance = clz.newInstance.call(this, arguments));
    };

    return clz;
};
Scene.prototype.on = function (name, fn, bind) {
    this.mEvents.on(name, fn, bind);
};
Scene.prototype.off = function (name) {
    this.mEvents.off(name);
};
Scene.prototype.toString = function () {
    return this.mTag + ':' + this.mId;
};

module.exports = Scene;
